import pandas as pd
from sklearn import linear_model
from sklearn.preprocessing import StandardScaler

scaler = StandardScaler()

df = pd.read_csv('cars.csv')
x = df[['Weight', 'Volume']]
y = df['CO2']

regr = linear_model.LinearRegression()
regr.fit(x, y)

print(regr.coef_)

predictedCO2 = regr.predict([[2300, 1300]])
print(predictedCO2)

# 缩放 Scale Features
x['Volume'] = df[['Volume']] / 1000
# print(x)
# standardization 标准化缩放方法 z = (x - u) / s
x_scaled = scaler.fit_transform(x)
# print(x_scaled)
regr = linear_model.LinearRegression()
regr.fit(x_scaled, y)

scaled = scaler.transform([[2300, 1.3]])
predictedCO2 = regr.predict([scaled[0]])
print(predictedCO2)
